package com.wsl.encry;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.ui.Messages;

@Service
@State(name = "EncryptionSettings", storages = {@Storage(value = "EncryptionSettings.xml")})
public final class MyPluginState implements PersistentStateComponent<MyPluginState> {
	private String key = "";
	public static MyPluginState getInstance() {
		return ApplicationManager.getApplication().getService(MyPluginState.class);
	}
	@Override
	public MyPluginState getState() {
		return this;
	}
	@Override
	public void loadState(MyPluginState state) {
		key = state.key;
	}
	// Accessor methods for your configuration data
	public String getKey() {
		if (key == null) {
			Messages.showMessageDialog("请先配置密钥","提醒", Messages.getInformationIcon());
			throw new IllegalStateException("Key not set");
		}
		return key;
	}
	public void setKey(String value) {
		key = value;
	}
}